package com.jn.exam.webSocket.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author 江南大学1033190417
 * @date 2022/3/5 15:57
 */
@Component
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
    @Value("${server.port}")
    private int serverPort;

    public String getUrl(){
        InetAddress address=null;
        try {
            address=InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return address.getHostAddress()+":"+this.serverPort;
    }

    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {

    }
}
